﻿using System;
using System.Collections;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace Group_Mail
{
    [Serializable]
    public class Recipient : IXmlSerializable
    {
        private readonly Hashtable data;

        public Recipient()
        {
            data = new Hashtable();
        }

        #region IXmlSerializable Members

        public XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(XmlReader reader)
        {
            reader.Read();
            while (reader.NodeType != XmlNodeType.EndElement)
            {
                data[reader.Name] = reader.ReadInnerXml();
            }
            reader.Read();
        }

        public void WriteXml(XmlWriter writer)
        {
            foreach (DictionaryEntry item in data)
            {
                writer.WriteElementString(item.Key.ToString(), null, item.Value.ToString());
            }
        }

        #endregion

        public string GetFieldValue(string name)
        {
            if (data.Contains(name))
            {
                return (string) data[name];
            }
            return string.Empty;
        }

        public void SetFieldValue(string name, string value)
        {
            data[name] = value;
        }
    }
}